<?php
if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}

function print_pre_r($cat_list){
	print ( '<pre>' )  ;
	print_r ( $cat_list ) ;
	print ( '</pre>' ) ;
}

//autoExecute($table, $field_values, $mode = 'INSERT', $where = '', $querymode = '')
function cut_str($sourcestr,$cutlength) { //截取中文字符串
$returnstr=''; 
$i=0; 
$n=0; 
$str_length=strlen($sourcestr);//字符串的字节数 
while (($n<$cutlength) and ($i<=$str_length)) 
{ 
   $temp_str=substr($sourcestr,$i,1); 
   $ascnum=Ord($temp_str);//得到字符串中第$i位字符的ascii码 
   if ($ascnum>=224) //如果ASCII位高与224，
   { 
      $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范，将3个连续的字符计为单个字符       
      $i=$i+3;          //实际Byte计为3
      $n++;          //字串长度计1
   }
   elseif ($ascnum>=192) //如果ASCII位高与192，
   { 
      $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范，将2个连续的字符计为单个字符 
      $i=$i+2;          //实际Byte计为2
      $n++;          //字串长度计1
   }
   elseif ($ascnum>=65 && $ascnum<=90) //如果是大写字母，
   { 
      $returnstr=$returnstr.substr($sourcestr,$i,1); 
      $i=$i+1;          //实际的Byte数仍计1个
      $n++;          //但考虑整体美观，大写字母计成一个高位字符
   }
   else             //其他情况下，包括小写字母和半角标点符号，
   { 
      $returnstr=$returnstr.substr($sourcestr,$i,1); 
      $i=$i+1;          //实际的Byte数计1个
      $n=$n+0.5;        //小写字母和半角标点等与半个高位字符宽...
   } 
} 

      /*if ($str_length>$cutlength){
          $returnstr = $returnstr . "...";//超过长度时在尾处加上省略号
      }*/
  return $returnstr; 
}

function msg_substr($str, $len, $charset="utf-8"){//中英文数字同等位截取
	//如果截取长度小于等于0，则返回空
	if( !is_numeric($len) or $len <= 0 ){
		return "";
	}
	//如果截取长度大于总字符串长度，则直接返回当前字符串
	$sLen = strlen($str);
	if( $len >= $sLen ){
		return $str;
	}
	//判断使用什么编码，默认为utf-8
	if ( strtolower($charset) == "utf-8" ){
		$len_step = 3; //如果是utf-8编码，则中文字符长度为3
	}else{
		$len_step = 2; //如果是gb2312或big5编码，则中文字符长度为2
	}
	//执行截取操作
	$len_i = 0; //初始化计数当前已截取的字符串个数，此值为字符串的个数值（非字节数）
	$substr_len = 0; //初始化应该要截取的总字节数
	for( $i=0; $i < $sLen; $i++ ){
		if ( $len_i >= $len ) break; //总截取$len个字符串后，停止循环
		//判断，如果是中文字符串，则当前总字节数加上相应编码的中文字符长度
		if( ord(substr($str,$i,1)) > 0xa0 ){
			$i += $len_step - 1;
			$substr_len += $len_step;
		}else{ //否则，为英文字符，加1个字节
			$substr_len ++;
		}
		$len_i ++;
	}
	$result_str = substr($str,0,$substr_len );
	return $result_str;
}
function msg_cut_inarr($str,$len){
	$res_arr=array();
	$i=0;
	$str_=$str;
	do {
		$res_arr[$i]=msg_substr($str_,$len);
		$str_all="";
		if(count($res_arr)>0){
			foreach ($res_arr as $key=>$val){
				$str_all.=$val;
				
			}
		}
		$str_=substr($str,strlen($str_all));
		$i++;
	}while (strlen($str_all)<strlen($str));
	return $res_arr;
}
function get_url_here($ur_here){
	$url='';
	if(empty($ur_here)){
		return $url;
	}
	foreach ($ur_here as $key=>$val){
		if($val['txt']!=''){
			if($val['url']!=''){
				$url.="<a href='".$val['url']."'>".$val['txt']."</a>&nbsp&nbsp";
			}else{
				$url.=$val['txt']."&nbsp&nbsp";
			}
		}
	}
	return $url;
}
function get_ip_place(){

	$ip=@file_get_contents("http://fw.qq.com/ipaddress");
    $ip=mb_convert_encoding($ip, "UTF-8", "GBK"); 

	$ip=str_replace('"',' ',$ip);

	$ip2=explode("(",$ip);

	$a=substr($ip2[1],0,-2);

	$b=explode(",",$a);

	$pro=explode('省',$b[2]);
	$b[2]=$pro[0];
	$ct=explode('市',$b[3]);
	$b[3]=$ct[0];
	
	return $b;

}

function get_html_val($html_val){
	
	if(is_array($html_val)){
		foreach ($html_val as $key=>$val){
			get_html_val($val);
		}
	}else{
		$res_val=htmlspecialchars(stripslashes(urldecode(trim($html_val))));
	}

	return $res_val;
}


function number_into_ch($number){
	$res=array();

	$ch_arr=array('千','百','十','万','千','百','十','元','','角','分');
	$num_ch_arr=array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖','拾');
	$break_num=explode('.',$number);
	$first_sub=$break_num[0];//小数位前段
	$second_sub=$break_num[1];//小数位后
	//$num_arr_f=str_split($first_sub);
	//$num_arr_s=str_split($second_sub);
	$first_len=strlen($first_sub);
	$second_len=strlen($second_sub);
	$all_len_f=8;//小数点前支持到千万位
	$all_len_s=2;//小数点后支持到分位
	if($first_len>$all_len_f){//超过千万，返回空
		return $res;
	}elseif ($first_len<$all_len_f){
		$cut_len=$all_len_f-$first_len;
		for ($i=1;$i<=$cut_len;$i++){
			$number="0".$number;
		}
	}
	if($second_len>$all_len_s){//超过千万，返回空
		$number=sub_str($number,0,$all_len_f+$all_len_s+1);
	}elseif ($second_len<$all_len_s){
		$cut_len=$all_len_s-$second_len;
		if($second_len==0){
			$number.=".";
		}
		for ($i=1;$i<=$cut_len;$i++){
			$number.="0";
		}
	}
	$num_arr=str_split($number);
	if(!empty($num_arr)){
		foreach ($num_arr as $key=>$val){
			$res[0].=$num_ch_arr[$val].$ch_arr[$key];
			$res[1][$key]=$num_ch_arr[$val];
		}
	}
	return $res;
	
}
/**
 * 短信发送接口
 * @param   string  $phone  接收方电话
 * @param   string  $text 短信内容
 *   
 * 返回值：整数类型。如果短信发送成功，则返回1，否则为其他的数字。分别如下：
-14、发送号码为空；
-11、群发号码超过100个；
-15、短信内容为空；
-5、短信内容超长
-99、其他错误返回-99
帐号的余额不足也将导致短信发送失败。
 */
function send_message($phone, $text,$userName='', $password='', $subId=''){
	include_once('msg/cls_postmsgAPI.php');
	global $msg_username,$msg_pass;
	if(empty($userName)){$userName=$msg_username;}
	if(empty($password)){$password=$msg_pass;}
	$phone="$phone";
	$msg_arr=msg_cut_inarr($text,63);
	if(count($msg_arr)>0){
		//set_time_limit(3);
		foreach ($msg_arr as $key=>$val){
			$text=mb_convert_encoding($val, "GB2312","UTF-8");
			$result = Msg_PostSingle($userName, $password, $phone, $text,$subId);
		}
	}
	if($result==0){//发送成功返回0,本系统则记录为1
		$result=1;
	}
	return $result;
}
function goto_send_message($phone,$text,$txt_type=1,$path='',$result=1){
	//短信发送都转到该页面，以免短信服务器端请求时间过长 $result=0不返回任何信息且不用登陆即可发送，否则都要
	///1为全部电话同一内容，2为各个对话对应各自内容
	echo "<form id='to_send_message_frm' name='to_send_message_frm' action='".$path."send_msg.php' target=\"_blank\" method=\"post\">";
	//print_r($phone);
	if(is_array($phone)&&count($phone)>0){
		foreach ($phone as $key=>$val){
			echo "<input type='hidden' name='phone[$key]' value='$val'/>";
		}
	}else{
		echo "<input type='hidden' name='phone' value='$phone'/>";
	}
	if($txt_type==1){
		$text=is_array($text)?$text[0]:$text;
		echo "<input type='hidden' name='text' value='$text'/>";
	}elseif($txt_type==2){
		if(is_array($text)&&count($text)>0){
			foreach ($text as $key=>$val){
				echo "<input type='hidden' name='text[$key]' value='$val'/>";
			}
		}
	}
	echo "<input type='hidden' name='txt_type' value='$txt_type'/>";
	echo "<input type='hidden' name='result' value='$result'/>";
	echo "</form>";
	echo "<script language=\"javascript\">document.to_send_message_frm.submit();</script>";
}
/**
 * 生成编辑器
 * @param   string  input_name  输入框名称
 * @param   string  input_value 输入框值
 */
function create_html_editor($input_name, $input_value = '')
{
    global $smarty;
    include_once('fckeditor/fckeditor.php'); // 包含 html editor 类文件
    $editor = new FCKeditor($input_name);
    $editor->BasePath   = './includes/fckeditor/';
    $editor->ToolbarSet = 'Normal';
    $editor->Width      = '100%';
    $editor->Height     = '450';
    $editor->Value      = $input_value;
    $FCKeditor = $editor->CreateHtml();
    $smarty->assign('FCKeditor', $FCKeditor);
}
function zc_rand($length){//随机生成长度为$length的字符串 
    $pattern = 'abcdefg12345hijklmnopqrst67890uvwxyz';    //字符池 
    for($i=0;$i<$length;$i++) 
    { 
        $key .= $pattern{mt_rand(0,35)};    //生成php随机数 
    } 
    return $key; 
} 
function count_time($old_time,$new_time){//$old_time,$new_time为时间戳,返回两时间戳相差n年n月n日
	if($old_time<$new_time){
		$time_small=$old_time;
		$time_big=$new_time;
	}else {
		$time_big=$old_time;
		$time_small=$new_time;
	}
	//print_r("</br>count_time1:".$time_big);
	//print_r("</br>count_time2:".$time_small);
    $cut_time_s=$time_big-$time_small;//共时差 单位是秒
    $cut_time_d=$cut_time_s/(3600*24);//共时差 单位是天 
    
    $cut_time_year=intval($cut_time_d/365);//折算相差几年
    $cut_time_d_leaf=fmod($cut_time_d,365);//剩下相差天数 单位是天 
    
    $cut_time_month=intval($cut_time_d_leaf/30);//剩下天数 折算几月
    $cut_time_d_leaf=sprintf('%d',fmod($cut_time_d_leaf,30));//剩下相差天数 单位是天 
    
	$str="";
	if($cut_time_year>0){$str.=$cut_time_year."年";}
	if($cut_time_month>0){$str.=$cut_time_month."个月";}
	if($cut_time_d_leaf>0){$str.=$cut_time_d_leaf."日";}

	return $str;
}
function count_year($old_time,$new_time){//$old_time,$new_time为时间戳,返回两时间戳相差n年
	if($old_time<$new_time){
		$time_small=$old_time;
		$time_big=$new_time;
	}else {
		$time_big=$old_time;
		$time_small=$new_time;
	}
    $cut_time_s=$time_big-$time_small;//共时差 单位是秒
    $cut_time_d=$cut_time_s/(3600*24);//共时差 单位是天 
    
    $cut_time_year=intval($cut_time_d/365);//折算相差几年
    $cut_time_d_leaf=fmod($cut_time_d,365);//剩下相差天数 单位是天 
    
    $cut_time_month=intval($cut_time_d_leaf/30);//剩下天数 折算几月
    $cut_time_d_leaf=fmod($cut_time_d_leaf,30);//剩下相差天数 单位是天 
    
	$str="";
	if($cut_time_year>=0){$str.=$cut_time_year."年";}
	return $str;
}
function count_that_time($inf){//推算inf['hour']，inf['day']，inf['month']，inf['year']之后的时间戳，如inf['month']=3则返回三个月之后的时间戳
	$from_time_line=intval($inf['from_time_line']);
	if($from_time_line<=0){
		$that_time=$now_time=time();
	}else{
		$that_time=$now_time=$from_time_line;
	}
	
	$now_month=date('m',$now_time);
	$now_year=date('Y',$now_time);
	if(empty($inf)){return $now_time;}
	$add_seconds=0;//增加的秒数
	$months=0;
	if(!empty($inf['day'])||!empty($inf['hour'])){
		$that_time+=($inf['day']*24+$inf['hour'])*3600;
	}
	$that_time_txt=date('Y-m-j H:i:s',$that_time);
	$that_month=date('m',$that_time);
	$that_year=date('Y',$that_time);
	$that_tail=date('j H:i:s',$that_time);
	if(!empty($inf['month'])||!empty($inf['year'])){
		$months=$inf['year']*12+$inf['month'];
	}
	$to_end_month=12-$now_month;//还差几个月到本年末
	if($months<=$to_end_month){
		$that_time=strtotime($that_year.'-'.($that_month+$months).'-'.$that_tail);
	}else{
		$months-=$to_end_month;
		$that_year++;
		$that_year+=intval($months/12);
		$that_month+=fmod($months,12)-1;
		$that_time=strtotime($that_year.'-'.($that_month).'-'.$that_tail);
	}
	return $that_time;
	
}

function cut_days_hours($from_time,$to_time){//$from_time,$to_time为时间戳,返回两时间戳相差n年n月n日
	$days_hours=array('days'=>'','hours'=>'');
	if($from_time>=$to_time){return $days_hours;}
	$cut_time=$to_time-$from_time;//时差，(时间戳)
	
	$days_hours['days']=intval($cut_time/(3600*24));
	$days_hours['hours']=intval(fmod($cut_time,(3600*24))/3600);
	if(fmod(fmod($cut_time,(3600*24)),3600)>0){
		$days_hours['hours']++;//如果有超出几分钟，算多一个小时；
	}
	return $days_hours;
}
function createtable_hy($sql, $dbcharset) {
	$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
	$type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
	return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
	(mysql_get_server_info() > '4.1' ? " ENGINE=$type default CHARSET=".UC_DBCHARSET : " TYPE=$type");
}

/**
 * 执行经过处理的sql文件，sql文件不包含注释文字，不包含所在的数据库语句
 *
 * @access  public
 * @param   string  $sqlfile    经过处理的sql文件，sql文件不包含注释文字，不包含创建数据库语句
 * @param   string  $db_name   数据库名字
 * @return  boolen   
 */
function query_sqlfile($sqlfile,$db_name,$type='') {//$type:sql语句类型：创建，插入数据
	global $db,$ecs;
	if(empty($sqlfile)||empty($db_name)){return false;}
	if(!file_get_contents($sqlfile)){return false;}
	$obj_db=set_db_cp($db_name);//建立企业数据库对象
	if($obj_db===true){return false;}//能连接到$dbname表示数据库存在则返回

	$sql_txt = file_get_contents($sqlfile);
	$sql_txt = str_replace("\r", "\n", $sql_txt);
    $sql_txt = str_replace("\r\n", "\n", $sql_txt);

    if($type=='insert'){
    	$sql_db="INSERT INTO `".$db_name."`.";
    	$sql_txt =str_replace('INSERT INTO ',$sql_db, $sql_txt);
    	$expquery = explode(");", $sql_txt);
//print_r($sql_txt);return ;
    	foreach($expquery as $key=>$val) {
    		$val=trim($val);
    		if(empty($val)){unset($expquery[$key]);continue;}
    		$expquery[$key]=$val.")";
    		//echo $val."--<br/>";
    	}
    }else{
    	$sql_db="CREATE DATABASE IF NOT EXISTS $db_name;";
    	$sql_txt=$sql_db.$sql_txt;

    	$sql_db="TABLE `".$db_name."`.";
    	$sql_txt =str_replace('TABLE ',$sql_db, $sql_txt);
    	$expquery = explode(";", $sql_txt);
    }
//print_r($expquery);
//return ;
	foreach($expquery as $sql) {
		$sql = trim($sql);
		if($sql == ''||$sql[0] == '#'||$sql[0] =='-'||$sql[0] == '/') continue;
        if(strtoupper(substr($sql, 0, 12)) == 'CREATE TABLE') {
			$db->query(createtable_hy($sql, UC_DBCHARSET));
		} else {
			$db->query($sql);
		}
	}
	$obj_db=set_db_cp($db_name);//建立企业数据库对象
	if($obj_db===false){return false;}//创建数据库失败则返回
	return true;
}
function query_sqltxt($sql_txt,$sql_db=''){//执行多条sql语句，不返回数据
	global $db,$ecs;
	
	if(!empty($sql_db)){
		//$sql_txt=str_ireplace('TABLE ','TABLE '.$sql_db.'.', $sql_txt);
		//$sql_txt=str_ireplace('INSERT INTO ','INSERT INTO '.$sql_db.'.', $sql_txt);
		//$sql_txt=str_ireplace('RENAME TO ','RENAME TO '.$sql_db.'.', $sql_txt);
		//$sql_txt=str_ireplace('FROM ','FROM '.$sql_db.'.', $sql_txt);
		$sql_txt=str_ireplace('[#name#]',$sql_db, $sql_txt);
		//建立企业数据库对象
	    if(set_db_cp($sql_db)===false){return false;}//不能连接到$dbname则返回
	    
	}
	$sql_txt = str_replace("\r", "\n", $sql_txt);
	$sql_txt = str_replace("\\", "", $sql_txt);
    $sql_txt = str_replace("\r\n", "\n", $sql_txt);
    //$sql_txt = str_replace("`", "", $sql_txt);
   //echo $sql_txt."<br/>";
	$expquery = explode(";", $sql_txt);
	foreach($expquery as $sql) {
		$sql = trim($sql);
		//echo $sql = trim($sql);echo "<br/><br/>";continue;
		if($sql == ''||$sql[0] == '#'||$sql[0] =='-'||$sql[0] == '/') continue;
        if(strtoupper(substr($sql, 0, 12)) == 'CREATE TABLE') {
			$res=$db->query(createtable_hy($sql, UC_DBCHARSET));
		}else {
			$res=$db->query($sql);
		}
	}
	return $res;
}
function query_sql_data($sql_txt,$all=0){//执行sql语句，并返回查询结果
	global $db,$ecs;
	$res=array();
	if(empty($sql_txt)){return $res;}
	$sql_txt = str_replace("\'", "'", $sql_txt);
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}

	$sql = "select count(*) as num from (" .$sql_txt.")";       
	
	$res=$db->getAll($sql_txt);
	$num_db=count($res);//总记录数
	$page_db=intval($num_db/$page_num)+($num_db%$page_num==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
    $res=$db->getAll($sql_txt.$limit);
    $i=0;
    foreach ($res as $key=>$val){
    	$i++;
        $res[$key]['num_db']=$num_db;
        $res[$key]['page_db']=$page_db;
        $res[$key]['key']=$i;
    }
   	return $res;
}
//------------------------------------------------
function get_first_ele($arr){//数组取第一元素
	if(!is_array($arr)){return $arr;}
	if(empty($arr)){return "";}
	if(!empty($arr)){
		 foreach ($arr as $key=>$val) {
		 	return $val;
		 }
	}
}

//-------------------------------------------------

function dirsize($dirpath,$unit=''){//返回指定目录的总大小，和包含的子目录数，文件数 $unit:单位=KB,MB,''=Bit
    
    $thisdirstat = array('filesize'=>0,"files"=>0,"dirs"=>0);
    
    if (false ==($dirhandle = @opendir($dirpath))) return $thisdirstat ;
    while (false !== ($name = readdir($dirhandle))){
        if ($name == "." or $name == "..") continue;
        if (!is_dir($dirpath.DIRECTORY_SEPARATOR.$name)){
            $thisdirstat["filesize"] += filesize($dirpath.DIRECTORY_SEPARATOR.$name);
            ++$thisdirstat["files"];
            }
        else{
            ++$thisdirstat["dirs"];
            $subdirstat = dirsize($dirpath.DIRECTORY_SEPARATOR.$name);
            $thisdirstat["filesize"] += $subdirstat["filesize"]; //目录内所有文件的大小总和
            $thisdirstat["files"] += $subdirstat["files"]; //文件数
            $thisdirstat["dirs"] += $subdirstat["dirs"]; //子目录数
        };
    };
    closedir($dirhandle);
    if($unit=='KB'){
    	$thisdirstat["filesize"]=sprintf('%.2f',$thisdirstat["filesize"]/1024);
    }elseif ($unit=='MB'){
    	$thisdirstat["filesize"]=sprintf('%.2f',$thisdirstat["filesize"]/1024/1024);
    }
    return $thisdirstat;

};

//-----------------------------------------------
function hy_header($string, $target='_self'){//页面跳转
	if($target=='_self'){
		$location="window.location";
	}elseif($target=='_top'){
		$location="window.top.location";
	}else {
		$location="window.top.".$target.".location";
		//$location=$target.".location";
	}
    echo '<script type="text/javascript">'.$location.'.href="' . $string . '";</script>';
}

function page_select($curr_page,$page_count,$key_page,$page_k=''){
	//下拉选择分页处理，$current_page当前页，$page_count总页数，$key_page参数串，网页参数格式,$page_k page名称补全
	global $smarty;
	$page_count=intval($page_count);
	$curr_page=intval($curr_page);
	//if($page_count<=0){return false;}
	$page_arr=array();
	$from_i=1;
	$to_i=$page_count;
	
	
	for ($i=$from_i;$i<=$to_i;$i++){
		array_push($page_arr,$i);
	}
	$smarty->assign('page_arr',$page_arr);
	$smarty->assign('page'.$page_k,$curr_page);
	$smarty->assign('key_page',$key_page);
}
//-------------------------------------------------------------------



function random_string(){
	$str = '';
	for($i = 0; $i < 9; $i++) {
		$str .= mt_rand(0, 9);
	}
	$str=gmtime().$str;
	return $str;
}

//feng 2010-7-2
//服务中心公共资讯，上传文件
function upload_sc_file($html_name,$allowtypes=array()){

	//目录
	$dir=date('Ym');
	$subdir='data/sc_upfiles/'.$dir;
	$dir=ROOT_PATH.$subdir;
	if (!file_exists($dir))
        {
            if (!make_dir($dir))
            {
				return false;
            }
     }

	$msg=array("error"=>0,"msg"=>"");
	if(empty($html_name)){
		return $msg=array("error"=>3,"msg"=>"没有上传文件");
	}

	if ($_FILES[$html_name]['error'] == 0){

		//扩展名
		$file_type=end(explode(".",$_FILES[$html_name]['name']));
		if(strlen($file_type)>0){
			$file_name=substr($_FILES[$html_name]['name'],0,-strlen($file_type)-1);
		}else{
			$file_name=$_FILES[$html_name]['name'];
		}
		if(!empty($allowtypes)&&!in_array($file_type,$allowtypes)){
			return $msg=array("error"=>4,"msg"=>"扩展名不符要求 ");
		}
		

		 //文件名
		 $filename='';
		 while(empty($filename)){			
			$str=random_string();
			$filename=$str.'.'.$file_type;
			if(file_exists($dir.'/'.$filename)){
				$filename='';
			}
		 }
		 
		 //上传文件
		 if (!move_upload_file($_FILES[$html_name]['tmp_name'], $dir.'/'.$filename))
        {
            return $msg=array("error"=>5,"msg"=>"上传文件失败");
        }
		return $msg=array("error"=>0,"msg"=>"上传文件成功","filepath"=>$subdir.'/'.$filename,"filename"=>$file_name);

	}elseif ($_FILES[$html_name]['error'] == 1||
		$_FILES[$html_name]['error'] == 2){
           return  $msg=array("error"=>1,"msg"=>"上传文件太大");
    }elseif ($_FILES[$html_name]['error'] == 4){
           return $msg=array("error"=>2,"msg"=>"没有上传文件");
    }

}

//------------------------------------------------------------------------------------------------
function uploade_imge($html_name,$save_path=''){//$html_name为html页面文件控件名称,save_path为保存路径
	include_once('cls_image.php');
    $image = new cls_image($_CFG['bgcolor']);
    
	$imge_path=array("error"=>0,"image"=>"","msg"=>"");
	if(empty($html_name)){
		return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有上传图片");
	}
   if ($_FILES[$html_name]['error'] == 0){
            if (!$image->check_img_type($_FILES[$html_name]['type'])){
                $imge_path=array("error"=>1,"image"=>"","msg"=>"上传的图片格式错误！图片没有更新，其他信息已经更新");
            }else{
            	$save_name=$image->random_filename();
            	$save_name.=$_FILES[$html_name]['type'];
            	$logo = $image->upload_image($_FILES[$html_name],$save_path);
            	if ($logo !== false){
                	return $imge_path=array("error"=>0,"image"=>$logo,"msg"=>"上传保存图片成功！");
            	}else {
            		return $imge_path=array("error"=>1,"image"=>"","msg"=>"保存上传的图片失败！");
            	}
            }
        }elseif ($_FILES[$html_name]['error'] == 1||$_FILES[$html_name]['error'] == 2){
           return  $imge_path=array("error"=>1,"image"=>"","msg"=>"上传的图片太大！图片没有更新，其他信息已经更新");
        }elseif ($_FILES[$html_name]['error'] == 4){
           return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有上传图片");
        }
}
//------------------------------------------------------------------------------------------------
function get_uploade_xls($xls_name,$save_path=''){//$xls_name为html页面文件控件名称,save_path为保存路径
	include_once('cls_image.php');
    $image = new cls_image($_CFG['bgcolor']);
    $result=array();
    include_once('excel/reader.php');//读取excel数据的类
    //实例化excel类
    $data = new Spreadsheet_Excel_Reader();
    //选择编码
    $data->setOutputEncoding(EC_CHARSET);

	$imge_path=array("error"=>0,"file"=>"","msg"=>"");
	if(empty($xls_name)){
		return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有上传EXCEL文件");
	}
   if ($_FILES[$xls_name]['error'] == 0){
            if (!$image->check_xls_type($_FILES[$xls_name]['type'])){
                $imge_path=array("error"=>1,"file"=>"","msg"=>"上传的 EXCEL 文件格式错误");
            }else{
            	$save_name=$image->random_filename();
            	$save_name.=$_FILES[$xls_name]['type'];
            	$xls = $image->upload_xls($_FILES[$xls_name],$save_path);
            	if ($xls !== false){
            		$file_path=ROOT_PATH.$xls;
            		$read_res=$data->read($file_path); 
            		if($read_res===false){return 'old_file';}
            		$xls_data=$data->sheets[0]['cells'];
            		$result=array('data'=>$xls_data,'file'=>$file_path);
                	return $result;
            	}else {
            		return $imge_path=array("error"=>1,"image"=>"","msg"=>"导入EXCEL文件失败！");
            	}
            }
        }elseif ($_FILES[$html_name]['error'] == 1||$_FILES[$html_name]['error'] == 2){
           return  $imge_path=array("error"=>1,"image"=>"","msg"=>"导入EXCEL文件太大！");
        }elseif ($_FILES[$html_name]['error'] == 4){
           return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有选择要导入的文件");
        }
}
//-----------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
function get_uploade_csv($csv_name,$save_path=''){//$xls_name为html页面文件控件名称,save_path为保存路径
	include_once('cls_image.php');
    $image = new cls_image($_CFG['bgcolor']);
    $result=array();

	$imge_path=array("error"=>0,"file"=>"","msg"=>"");
	if(empty($csv_name)){
		return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有上传CSV文件");
	}
	$file_type=end(explode(".",$_FILES[$csv_name]['name']));
   if ($_FILES[$csv_name]['error'] == 0){
            if ($file_type!='csv'){
                $imge_path=array("error"=>1,"file"=>"","msg"=>"上传的 CSV 文件格式错误");
            }else{
            	$save_name=$image->random_filename();
            	$save_name.=$file_type;
            	$csv = $image->upload_csv($_FILES[$csv_name],$save_path);
            	if ($csv !== false){
            		$csv_data=array();
            		$file_path=ROOT_PATH.$csv;
            		$handle = fopen($file_path,"r");
            		while ($data = fgetcsv($handle,'', ",")) {
            			$num = count($data);
            			$row++;
            			for ($c=0; $c < $num; $c++) {
            				//$csv_data[$row][$c+1]=$data[$c];
            				$csv_data[$row][$c+1]=mb_convert_encoding($data[$c], "UTF-8", "GBK");
            			}
            		}
            		$result=array('data'=>$csv_data,'file'=>$file_path);
                	return $result;
            	}else {
            		return $imge_path=array("error"=>1,"image"=>"","msg"=>"导入CSV文件失败！");
            	}
            }
        }elseif ($_FILES[$html_name]['error'] == 1||$_FILES[$html_name]['error'] == 2){
           return  $imge_path=array("error"=>1,"image"=>"","msg"=>"导入CSV文件太大！");
        }elseif ($_FILES[$html_name]['error'] == 4){
           return $imge_path=array("error"=>2,"image"=>"","msg"=>"没有选择要导入的文件");
        }
}
//-----------------------------------------------------------------------

//------------------------------------------------------ -----------------
function get_province_inf($id='',$name=''){//读取省份列表信息
	global $as,$db;
	$list=array();
	if(empty($id)&&empty($name)){return $list;}
	if(!empty($id)){
		$wh=" where provinceID='$id' ";
	}else{
		$wh=" where province like'%$name%' ";
	}
	$sql = "select * from " .$as->table('province'). $wh;
    $list=$db->getRow($sql);
	return $list;
}
function get_city_inf($id='',$name=''){//读取市信息
	global $as,$db;
	$list=array();
	if(empty($id)&&empty($name)){return $list;}
	if(!empty($id)){
		$wh=" where cityID='$id' ";
	}else{
		$wh=" where city like'%$name%' ";
	}
	$sql = "select * from " .$as->table('city'). $wh;
    $list=$db->getRow($sql);
	return $list;
}
function get_province(){//省份列表
	global $db,$as;
	$res=array();
	$sql ="";
    $sql = "select * from " .$as->table('province'); 
    $res=$db->getAll($sql);
    foreach ($res as $key=>$val){
    	$res[$key]['province']=trim($val['province']);
    }
	return $res;
}
function get_city(){//市列表
	global $db,$as;
	$res=array();
	$sql ="";
    $sql = "select * from " .$as->table('city'); 
    $res=$db->getAll($sql);
    foreach ($res as $key=>$val){
    	$res[$key]['city']=trim($val['city']);
    }
	return $res;
}

function get_hotel_city_list($inf=array(),$page=1,$page_num=10,$all=1){//酒店市表列表
	global $db,$as;
	$res=array();
	$sql ="";
	$wh=" where 1 ";
	if(!empty($inf['is_push'])){$wh.=" and is_push='".$inf['is_push']."'";}
	if(!empty($inf['is_hot'])){$wh.=" and is_hot='".$inf['is_hot']."'";}
	
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=7;
	}
	
	$num_db=$db->getOne("select count(*) as num from " .$as->table('hotel_city').$wh);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，
	
	$sql="";

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){
		$limit="";
	}
    $sql = "select * from " .$as->table('hotel_city').$wh." order by city_name_cn asc ".$limit; 

    $res=$db->getAll($sql);
    $i=0;
    foreach ($res as $key=>$val){
    	$i++;
        $res[$key]['num_db']=$num_db;
        $res[$key]['page_db']=$page_db;
        $res[$key]['key']=$i;
    }
	return $res;
}

function add_hotel_city($inf=array(),$inf_arr=array()){//酒店市表
	global $db,$as;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['hc_id']);
		$db->autoExecute($as->table('hotel_city'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){echo "hong";
			$db->autoExecute($as->table('hotel_city'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function get_area($city_id=''){//地区列表
	global $db,$as;
	$res=array();
	$sql ="";
	if(!empty($city_id)){
		$wh=" where father='".$city_id."'";
	}
    $sql = "select * from " .$as->table('area').$wh; 
    $res=$db->getAll($sql);
    foreach ($res as $key=>$val){
    	$res[$key]['area']=trim($val['area']);
    }
	return $res;
}
function get_province_city_area($area_id){//根据地区id取省市信息
	global $db,$as;
	$res=array();
	$sql ="";
    $sql = "select province,provinceID,city,cityID,area,areaID from " .$as->table('province')
    ." as p left join  " .$as->table('city')." as c on c.father=p.provinceID left join  "
     .$as->table('area')." as a on a.father=c.cityID where a.areaID='".$area_id."'"; 
    $res=$db->getRow($sql);
	return $res;
}
function get_nation(){//民族列表
	global $db,$as;
	$res=array();
	$sql ="";
    $sql = "select * from " .$as->table('nation'). " order by id asc "; 
    $res=$db->getAll($sql);
    foreach ($res as $key=>$val){
    	$res[$key]['nation']=trim($val['nation']);
    }
	return $res;
}


//------------------------------------------------------ -----------------

function get_home_bbs($fid='admin',$num=10,$cut_num=0,$isno=1){//获取bbs板块id=$fid的最新$num个主题
	global $dz,$db;
	$res=array();
	$e='';$wh='';$sql="";
	$wh=' where closed=0 ';
	if($isno==1){
		$e="=";
	}else {
		$e="<>";
	}
	if(is_numeric($fid)){
		$wh.=" and fid ".$e." '" . $fid . "'";
	}elseif($fid!='') {
		$wh.=" and author ".$e." '" . $fid . "'";
	}

    $sql = "select tid,subject from " .$dz->table('threads'). 
            $wh . " order by dateline desc limit 0,$num ";
    $res=$db->getAll($sql);
    if($cut_num>0){
    	foreach ($res as $key=>$val){
    	   $res[$key]['subject']=cut_str($val['subject'],$cut_num);
        }
    }
	return $res;
}

/**
 * 获得bbs分区或板块列表，可指定id进行获取
 *
 * @access  public
 * @param   string  $fid_arr     id数组，为空则返回全部
 * @param   string     $type   类型：分区group；板块forum（默认）
 * @return  array   $res 返回符合条件的所有记录
 */
function get_bbs_forums($fid_arr,$type='forum'){//获取bbs板块fid系列列表
	global $dz,$db;
	$res=array();
	if(empty($fid_arr)){return $res;}
	$wh=" where status=1 and type='$type' ";
	if(!empty($fid_arr)){
		$fid_str=implode(',',$fid_arr);
		$wh.=" and fid in(".$fid_str.")";
	}
	
   $sql = "select fid,type,name from " .$dz->table('forums'). 
            $wh . " order by fid asc ";
    $res=$db->getAll($sql);
	return $res;
}

/**
 * 获得bbs某板块主题列表
 *
 * @access  public
 * @param   int  $fid_arr     板块id数组，为空则返回全部
 * @param   string     $key   标题搜索关键字
 * @return  array   $res 返回符合条件的所有记录
 */
function get_bbs_threads($fid_arr,$key_s='',$page=1,$page_num=7){//获取bbs板块fid系列列表
	global $dz,$db;
	$res=array();
	$wh=" where closed=0  ";
	if(empty($fid_arr)){return $res;}
    if(is_array($fid_arr)){
    	foreach ($fid_arr as $key=>$val){
    		if(empty($val)){unset($fid_arr[$key]);}
    	}
    }
	$fid_str=implode(',',$fid_arr);
	if(!empty($fid_str)){
		$wh.=" and fid in(".$fid_str.") ";
	}
	

	if(!empty($key_s)) {
		$wh.=" and subject like '%".$key_s."%'";
	}
	
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=7;
	}
	
   
            
	$num_db=$db->getOne("select count(fid) as num from " .$dz->table('threads').$wh);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，
	
	$sql="";

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
    $sql = "select tid,fid,author,subject,dateline,lastpost,lastposter,views,replies from " .$dz->table('threads'). 
            $wh . " order by lastpost desc ".$limit;
    $res=$db->getAll($sql);
    $i=0;
    foreach ($res as $key=>$val){
    	$i++;
    	$res[$key]['subject']=cut_str($val['subject'],28)."...";
    	if(!empty($res[$key]['dateline'])){$res[$key]['dateline']=date('Y-m-d',$val['dateline']);}
    	if(!empty($res[$key]['lastpost'])){$res[$key]['lastpost']=date('Y-m-d',$val['lastpost']);}
        $res[$key]['num_db']=$num_db;
        $res[$key]['page_db']=$page_db;
        $res[$key]['key']=$i;
    }
	return $res;
}
//===============================================================

function get_users_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取用户表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['user_rank'])){$wh.=" and user_rank='".$search_inf['user_rank']."'";}
	if(!empty($search_inf['is_validated'])){$wh.=" and is_validated='".$search_inf['is_validated']."'";}
	if(!empty($search_inf['is_special'])){$wh.=" and is_special='".$search_inf['is_special']."'";}
	if(!empty($search_inf['sex'])){$wh.=" and sex='".$search_inf['sex']."'";}
	if(!empty($search_inf['garden_manager'])){$wh.=" and garden_manager='".$search_inf['garden_manager']."'";}
	
	$sql = "select count(user_id) as num from " .$ecs->table('users').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('users').$wh." order by user_id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_users($inf=array()){//添加用户表
	global $db,$ecs,$_CFG;
	/* 增加是否关闭注册 */
    if ($_CFG['shop_reg_closed'])
    {
        return false;
    }
    else
    {
        include_once('lib_passport.php');

        $username = isset($inf['username']) ? trim($inf['username']) : '';
        $password = isset($inf['password']) ? trim($inf['password']) : '';
        $email    = empty($inf['email']) ?   $username.'@as51.com':trim($inf['email']);
        $other['msn'] = isset($inf['msn']) ? $inf['msn'] : '';
        $other['qq'] = isset($inf['qq']) ? $inf['qq'] : '';
        $other['office_phone'] = isset($inf['office_phone']) ? $inf['office_phone'] : '';
        $other['home_phone'] = isset($inf['home_phone']) ? $inf['home_phone'] : '';
        $other['mobile_phone'] = isset($inf['mobile_phone']) ? $inf['mobile_phone'] : '';
        $sel_question = empty($inf['sel_question']) ? '' : $inf['sel_question'];
        $passwd_answer = isset($inf['passwd_answer']) ? trim($inf['passwd_answer']) : '';
        
        $address_arr=isset($inf['address']) ? $inf['address'] : array();
        $consignee_arr=isset($inf['consignee']) ? $inf['consignee'] : array();
        $tel_arr=isset($inf['tel']) ? $inf['tel'] : array();

        $list = array();
        //$sql  = 'SELECT user_id FROM ' .$ecs->table('admin_user').' where role_id='.GARDEN_ROLE_ID.' ORDER BY garden_num asc ';
        //$other['garden_manager'] = $GLOBALS['db']->getOne($sql);

        $back_act = isset($inf['back_act']) ? trim($inf['back_act']) : '';
//print_pre_r($email);return ;
    
        if (register($username, $password, $email, $other) !== false)
        {
            /*把新注册用户的扩展信息插入数据库*/
            $sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id';   //读出所有自定义扩展字段的id
            $fields_arr = $db->getAll($sql);

            $extend_field_str = '';    //生成扩展字段的内容字符串
            foreach ($fields_arr AS $val)
            {
                $extend_field_index = 'extend_field' . $val['id'];
                if(!empty($inf[$extend_field_index]))
                {
                    $temp_field_content = strlen($inf[$extend_field_index]) > 100 ? mb_substr($inf[$extend_field_index], 0, 99) : $inf[$extend_field_index];
                    $extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . $temp_field_content . "'),";
                }
            }
            $extend_field_str = substr($extend_field_str, 0, -1);

            if ($extend_field_str)      //插入注册扩展数据
            {
                $sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str;
                $db->query($sql);
            }
            if (!empty($address_arr)){//插入地址列表
            	foreach ($address_arr as $key=>$val){
            		$address_str = " ('" . $_SESSION['user_id'] . "', '" . $consignee_arr[$key] . "', '" . $val . "', '" . $tel_arr[$key] . "')";
            		$sql = 'INSERT INTO '. $ecs->table('user_address') . ' (`user_id`, `consignee`, `address`,`tel`) VALUES' . $address_str;
                    $db->query($sql);
            	}
            }

            /* 写入密码提示问题和答案 */
            if (!empty($passwd_answer) && !empty($sel_question))
            {
                $sql = 'UPDATE ' . $ecs->table('users') . " SET `passwd_question`='$sel_question', `passwd_answer`='$passwd_answer'  WHERE `user_id`='" . $_SESSION['user_id'] . "'";
                $db->query($sql);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
   
}
function edt_users($inf=array(),$inf_arr=array()){//编辑用户表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['user_id']);
		$db->autoExecute($ecs->table('users'), $inf_ok, 'UPDATE', 'user_id = ' . $inf['user_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('users'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_users($user_id){//删除用户表
	global $db,$ecs;
	if(empty($user_id)){return false;}

	$db->query("delete from ".$ecs->table('users')." where user_id='$user_id'");
    return true;	
}

function get_users($user_id,$user_name){//读取用户表
	global $db,$ecs;
	$res=array();
	if(empty($user_id)&&empty($user_name)){return $res;}
	if($user_id){
		$wh="  where user_id='$user_id'";
	}else{
		$wh="  where user_name='$user_name'";
	}
	$res=$db->getRow("select * from ".$ecs->table('users').$wh);
	return $res;	
}
function login_as51($username,$password){
	//登陆
	include_once('lib_passport.php');
	if ($user->login($username, $password,isset($_POST['remember'])))
    {
        update_user_info();
        recalculate_price();
        return true;
    }else{
    	return false;
    }
	
}
//------------------------------------------------------ -----------------

function get_user_address_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取用户地址表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['user_id'])){$wh.=" and user_id='".$search_inf['user_id']."'";}
	
	$sql = "select count(address_id) as num from " .$ecs->table('user_address').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('user_address').$wh." order by address_id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_user_address($inf=array(),$inf_arr=array()){//添加用户地址表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['address_id']);
		$db->autoExecute($ecs->table('user_address'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('user_address'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_user_address($inf=array(),$inf_arr=array()){//编辑用户地址表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['address_id']);
		$db->autoExecute($ecs->table('user_address'), $inf_ok, 'UPDATE', 'address_id = ' . $inf['address_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('user_address'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_user_address($address_id){//删除用户地址表
	global $db,$ecs;
	if(empty($address_id)){return false;}

	$db->query("delete from ".$ecs->table('user_address')." where address_id='$address_id'");
    return true;	
}

function get_user_address($address_id){//读取用户地址表
	global $db,$ecs;
	$res=array();
	if(empty($address_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('user_address')."  where address_id='$address_id'");
	return $res;	
}

//------------------------------------------------------ -----------------

function get_category_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取商品类表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['cat_id'])){$wh.=" and cat_id='".$search_inf['cat_id']."'";}
	if(!empty($search_inf['parent_id'])){$wh.=" and parent_id='".$search_inf['parent_id']."'";}
	if(!empty($search_inf['cat_id_arr'])){
		$id_str=implode(",",$search_inf['cat_id_arr']);
		$wh.=" and cat_id in (".$id_str.")";
	}
	if(!empty($search_inf['cat_id_in'])){
		$wh.=" and cat_id in (".$search_inf['cat_id_in'].")";
	}
	
	if(empty($search_inf['orderby'])){
		$orderby=" sort_order asc ";
	}else{
		$orderby=$search_inf['orderby'].' ';
	}
	$sql = "select count(cat_id) as num from " .$ecs->table('category').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('category').$wh." order by ".$orderby.$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_category($inf=array(),$inf_arr=array()){//添加商品类表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['cat_id']);
		$db->autoExecute($ecs->table('category'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('category'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_category($inf=array(),$inf_arr=array()){//编辑商品类表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['cat_id']);
		$db->autoExecute($ecs->table('category'), $inf_ok, 'UPDATE', 'cat_id = ' . $inf['cat_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('category'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_category($cat_id){//删除商品类表
	global $db,$ecs;
	if(empty($cat_id)){return false;}

	$db->query("delete from ".$ecs->table('category')." where cat_id='$cat_id'");
    return true;	
}

function get_category($cat_id){//读取商品类表
	global $db,$ecs;
	$res=array();
	if(empty($cat_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('category')."  where cat_id='$cat_id'");
	return $res;	
}
//------------------------------------------


//------------------------------------------

//------------------------------------------------------ -----------------

function get_order_info_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取订单表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['user_id'])){$wh.=" and user_id='".$search_inf['user_id']."'";}
	if(!empty($search_inf['order_status'])){$wh.=" and order_status='".$search_inf['order_status']."'";}
	if(!empty($search_inf['shipping_status'])){$wh.=" and shipping_status='".$search_inf['shipping_status']."'";}
	if(!empty($search_inf['pay_status'])){$wh.=" and pay_status='".$search_inf['pay_status']."'";}
	
	$sql = "select count(order_id) as num from " .$ecs->table('order_info').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('order_info').$wh." order by order_id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_order_info($inf=array(),$inf_arr=array()){//添加订单表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['order_id']);
		$db->autoExecute($ecs->table('order_info'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('order_info'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_order_info($inf=array(),$inf_arr=array()){//编辑订单表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['order_id']);
		$db->autoExecute($ecs->table('order_info'), $inf_ok, 'UPDATE', 'order_id = ' . $inf['order_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('order_info'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_order_info($order_id){//删除订单表
	global $db,$ecs;
	if(empty($order_id)){return false;}

	$db->query("delete from ".$ecs->table('order_info')." where order_id='$order_id'");
    return true;	
}

function get_order_info($order_id){//读取订单表
	global $db,$ecs;
	$res=array();
	if(empty($order_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('order_info')."  where order_id='$order_id'");
	return $res;	
}

//------------------------------------------------------ -----------------

function get_order_goods_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取订单内商品表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['order_id'])){$wh.=" and order_id='".$search_inf['order_id']."'";}
	if(!empty($search_inf['goods_sn'])){$wh.=" and goods_sn='".$search_inf['goods_sn']."'";}
	if(!empty($search_inf['goods_id'])){$wh.=" and goods_id='".$search_inf['goods_id']."'";}
	
	$sql = "select count(rec_id) as num from " .$ecs->table('order_goods').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('order_goods').$wh." order by goods_name asc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_order_goods($inf=array(),$inf_arr=array()){//添加订单内商品表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['rec_id']);
		$db->autoExecute($ecs->table('order_goods'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('order_goods'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_order_goods($inf=array(),$inf_arr=array()){//编辑订单内商品表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['rec_id']);
		$db->autoExecute($ecs->table('order_goods'), $inf_ok, 'UPDATE', 'rec_id = ' . $inf['rec_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('order_goods'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_order_goods($rec_id){//删除订单内商品表
	global $db,$ecs;
	if(empty($rec_id)){return false;}

	$db->query("delete from ".$ecs->table('order_goods')." where rec_id='$rec_id'");
    return true;	
}

function get_order_goods($rec_id){//读取订单内商品表
	global $db,$ecs;
	$res=array();
	if(empty($rec_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('order_goods')."  where rec_id='$rec_id'");
	return $res;	
}

//------------------------------------------------------ -----------------

function get_order_action_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取订单处理操作日志列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['order_id'])){$wh.=" and order_id='".$search_inf['order_id']."'";}
	
	$sql = "select count(action_id) as num from " .$ecs->table('order_action').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('order_action').$wh." order by action_id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_order_action($inf=array(),$inf_arr=array()){//添加订单处理操作日志
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['action_id']);
		$db->autoExecute($ecs->table('order_action'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('order_action'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_order_action($inf=array(),$inf_arr=array()){//编辑订单处理操作日志
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['action_id']);
		$db->autoExecute($ecs->table('order_action'), $inf_ok, 'UPDATE', 'action_id = ' . $inf['action_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('order_action'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_order_action($action_id){//删除订单处理操作日志
	global $db,$ecs;
	if(empty($action_id)){return false;}

	$db->query("delete from ".$ecs->table('order_action')." where action_id='$action_id'");
    return true;	
}

function get_order_action($action_id){//读取订单处理操作日志
	global $db,$ecs;
	$res=array();
	if(empty($action_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('order_action')."  where action_id='$action_id'");
	return $res;	
}

//------------------------------------------------------ -----------------




function get_goods_gallery_as_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取商品表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['goods_id'])){$wh.=" and goods_id='".$search_inf['goods_id']."'";}
	
	$sql = "select count(img_id) as num from " .$ecs->table('goods_gallery_as').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('goods_gallery_as').$wh." order by sort_order asc ".$limit;
	
    $res=$db->getAll($sql);
    
	return $res;
}

function add_goods_gallery_as($inf=array(),$inf_arr=array()){//添加商品表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['img_id']);
		$db->autoExecute($ecs->table('goods_gallery_as'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('goods_gallery_as'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_goods_gallery_as($inf=array(),$inf_arr=array()){//编辑商品表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['img_id']);
		$db->autoExecute($ecs->table('goods_gallery_as'), $inf_ok, 'UPDATE', 'img_id = ' . $inf['img_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('goods_gallery_as'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_goods_gallery_as($img_id){//删除商品表
	global $db,$ecs;
	if(empty($img_id)){return false;}

	$db->query("delete from ".$ecs->table('goods_gallery_as')." where img_id='$img_id'");
    return true;	
}

function get_goods_gallery_as($img_id){//读取商品表
	global $db,$ecs;
	$res=array();
	if(empty($img_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('goods_gallery_as')."  where img_id='$img_id'");
	return $res;	
}
//------------------------------------------------------ -----------------

function get_room_kind_list($search_inf=array(),$page=1,$page_num=10,$all=0){//读取商品表列表，
	global $db,$as;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['hotel_id'])){$wh.=" and hotel_id='".$search_inf['hotel_id']."'";}
	if(!empty($search_inf['hotel_id_in'])){$wh.=" and hotel_id in(".$search_inf['hotel_id_in'].")";}
	if(!empty($search_inf['rt_id_from'])){$wh.=" and rt_id_from='".$search_inf['rt_id_from']."'";}
	if(!empty($search_inf['hotel_id_from'])){$wh.=" and hotel_id_from='".$search_inf['hotel_id_from']."'";}
	if(!empty($search_inf['breakfast'])){$wh.=" and breakfast='".$search_inf['breakfast']."'";}
	
	/*
	if(!empty($search_inf['cat_id_in'])){
		$wh.=" and cat_id in (".$search_inf['cat_id_in'].")";
	}*/
	
	$sql = "select count(rt_id) as num from " .$as->table('room_kind').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$as->table('room_kind').$wh." order by booking_num desc ".$limit;
	
    $res=$db->getAll($sql);
    $i=0;
    foreach ($res as $key=>$val){
    	switch ($val['breakfast']){///早餐1单早2双早0无早
    		case '1':
    			$val['breakfast_txt']="单早";
    			break;
    		case '2':
    			$val['breakfast_txt']="双早";
    			break;
    		case '0':
    			$val['breakfast_txt']="无早";
    			break;
    	}

       $val['num_db']=$num_db;
       $val['page_db']=$page_db;
       $val['key']=++$i;
       
       $res2[]=$val;
    }
	return $res2;
}

function add_room_kind($inf=array(),$inf_arr=array()){//添加商品表
	global $db,$as;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['rt_id']);
		$db->autoExecute($as->table('room_kind'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($as->table('room_kind'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_room_kind($inf=array(),$inf_arr=array()){//编辑商品表
	global $db,$as;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['rt_id']);
		$db->autoExecute($as->table('room_kind'), $inf_ok, 'UPDATE', 'rt_id = ' . $inf['rt_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($as->table('room_kind'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_room_kind($rt_id){//删除商品表
	global $db,$as;
	if(empty($rt_id)){return false;}

	$db->query("delete from ".$as->table('room_kind')." where rt_id='$rt_id'");
    return true;	
}

function get_room_kind($rt_id){//读取商品表
	global $db,$as;
	$res=array();
	if(empty($rt_id)){return $res;}
	
	$res=$db->getRow("select * from ".$as->table('room_kind')."  where rt_id='$rt_id'");
	switch ($res['breakfast']){///早餐1单早2双早0无早
    		case '1':
    			$res['breakfast_txt']="单早";
    			break;
    		case '2':
    			$res['breakfast_txt']="双早";
    			break;
    		case '0':
    			$res['breakfast_txt']="无早";
    			break;
    	}
	return $res;	
}

//------------------------------------------------------ -----------------

function get_user_account_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取用户资金流动表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['user_id'])){$wh.=" and user_id='".$search_inf['user_id']."'";}
	if(!empty($search_inf['process_type'])){$wh.=" and process_type='".$search_inf['process_type']."'";}
	if(!empty($search_inf['is_paid'])){$wh.=" and is_paid='".$search_inf['is_paid']."'";}
	
	$sql = "select count(id) as num from " .$ecs->table('user_account').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('user_account').$wh." order by id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_user_account_zc($inf=array(),$inf_arr=array()){//添加用户资金流动表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['id']);
		$db->autoExecute($ecs->table('user_account'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('user_account'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_user_account_zc($inf=array(),$inf_arr=array()){//编辑用户资金流动表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['id']);
		$db->autoExecute($ecs->table('user_account'), $inf_ok, 'UPDATE', 'id = ' . $inf['id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('user_account'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_user_account_zc($id){//删除用户资金流动表
	global $db,$ecs;
	if(empty($id)){return false;}

	$db->query("delete from ".$ecs->table('user_account')." where id='$id'");
    return true;	
}

function get_user_account_zc($id){//读取用户资金流动表
	global $db,$ecs;
	$res=array();
	if(empty($id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('user_account')."  where id='$id'");
	return $res;	
}
//------------------------------------------------------ -----------------

function get_account_log_list_zc($search_inf=array(),$page=1,$page_num=10,$all=1){//读取用户帐户记录表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['change_type'])){$wh.=" and change_type='".$search_inf['change_type']."'";}
	if(!empty($search_inf['user_id'])){$wh.=" and user_id='".$search_inf['user_id']."'";}
	
	$sql = "select count(log_id) as num from " .$ecs->table('account_log').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('account_log').$wh." order by log_id desc ".$limit;
	
    $res=$db->getAll($sql);
    //foreach ($res as $key=>$val){
    //	$res2[$val['obj_id']][]=$val;
    //}
	return $res;
}

function add_account_log_zc($inf=array(),$inf_arr=array()){//添加用户帐户记录表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['log_id']);
		$db->autoExecute($ecs->table('account_log'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('account_log'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_account_log_zc($inf=array(),$inf_arr=array()){//编辑用户帐户记录表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['log_id']);
		$db->autoExecute($ecs->table('account_log'), $inf_ok, 'UPDATE', 'log_id = ' . $inf['log_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('account_log'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_account_log_zc($log_id){//删除用户帐户记录表
	global $db,$ecs;
	if(empty($log_id)){return false;}

	$db->query("delete from ".$ecs->table('account_log')." where log_id='$log_id'");
    return true;	
}

function get_account_log_zc($log_id){//读取用户帐户记录表
	global $db,$ecs;
	$res=array();
	if(empty($log_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('account_log')."  where log_id='$log_id'");
	return $res;	
}
//------------------------------------------
function add_account($inf){
	$account_log_data=array();
	$user_account_data=array();
	
	$account_log_data['user_id']=$inf['user_id'];
	$account_log_data['user_money']=$inf['money'];
	$account_log_data['change_time']=$inf['now_time'];
	$account_log_data['change_desc']=$inf['admin_note'];
	switch ($inf['type']){//account_log表操作类型，0为充值，1为提现，2为管理员调节，99为其他类型',
		case 1:
			$account_log_data['change_type']=0;
			$user_account_data['process_type']=0;
			break;
		case 2:
			$account_log_data['change_type']=1;
			$user_account_data['process_type']=1;
			break;
		case 3:
			$account_log_data['change_type']=2;
			$user_account_data['process_type']=2;//2为管理员调节
			break;	
		case 4:
			$account_log_data['change_type']=3;//系统自动扣款
			$user_account_data['process_type']=3;//系统自动扣款
			break;	
	}
	
	$user_account_data['user_id']=$inf['user_id'];
	$user_account_data['admin_user']=$inf['admin_user'];//操作该笔交易的管理员的用户名'
	$user_account_data['amount']=$inf['money'];
	$user_account_data['add_time']=$inf['now_time'];
	$user_account_data['paid_time']=$inf['now_time'];
	$user_account_data['admin_note']=$inf['admin_note'];
	$user_account_data['user_note']=$inf['user_note'];
	$user_account_data['is_paid']=$inf['is_paid'];//是否已经付款，０，未付；１，已付',
	
	add_account_log_zc($account_log_data);
	add_user_account_zc($user_account_data);	
}

//------------------------------------------------------ -----------------
function get_comment_as_list($search_inf=array(),$page=1,$page_num=10,$all=0){//读取用户对文章和产品等的评论表列表，
	global $db,$ecs;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['comment_type'])){$wh.=" and comment_type='".$search_inf['comment_type']."'";}
	if(!empty($search_inf['id_value'])){$wh.=" and id_value='".$search_inf['id_value']."'";}
	if(!empty($search_inf['status'])){$wh.=" and status='".$search_inf['status']."'";}
		
	$sql = "select count(comment_id) as num from " .$ecs->table('comment').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$ecs->table('comment').$wh." order by add_time desc ".$limit;
	
    $res=$db->getAll($sql);
    $caidi_cat_arr=explode(',',CAIDI_CAT_ID);
    $i=0;
    foreach ($res as $key=>$val){
    	$i++;
       if($val['add_time']>0){$val['add_time_txt']=date("Y-m-j H:i",$val['add_time']);}
       
       $val['num_db']=$num_db;
       $val['page_db']=$page_db;
       $val['key']=$i;
       
       $res2[]=$val;
    }
	return $res2;
}

function add_comment_as($inf=array(),$inf_arr=array()){//添加用户对文章和产品等的评论表
	global $db,$ecs;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['comment_id']);
		$db->autoExecute($ecs->table('comment'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('comment'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_comment_as($inf=array(),$inf_arr=array()){//编辑用户对文章和产品等的评论表
	global $db,$ecs;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['comment_id']);
		$db->autoExecute($ecs->table('comment'), $inf_ok, 'UPDATE', 'comment_id = ' . $inf['comment_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($ecs->table('comment'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_comment_as($comment_id){//删除用户对文章和产品等的评论表
	global $db,$ecs;
	if(empty($comment_id)){return false;}

	$db->query("delete from ".$ecs->table('comment')." where comment_id='$comment_id'");
    return true;	
}

function get_comment_as($comment_id){//读取用户对文章和产品等的评论表
	global $db,$ecs;
	$res=array();
	if(empty($comment_id)){return $res;}
	
	$res=$db->getRow("select * from ".$ecs->table('comment')."  where comment_id='$comment_id'");
	return $res;	
}


//------------------------------------------------------ -----------------

function get_biz_zone_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取商业区列表列表，
	global $db,$ecs,$as;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['city_id'])){$wh.=" and city_id='".$search_inf['city_id']."'";}else{return $res;}
	if(!empty($search_inf['is_hot'])){$wh.=" and is_hot='".$search_inf['is_hot']."'";}
	
	$sql = "select count(biz_id) as num from " .$as->table('biz_zone').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$as->table('biz_zone').$wh." order by is_hot desc,biz_name asc ".$limit;
	
    $res=$db->getAll($sql);
/*
    foreach ($res as $key=>$val){

    	$res[$key]=$val;
    }*/
	return $res;
}

function add_biz_zone($inf=array(),$inf_arr=array()){//添加商业区列表
	global $db,$as;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['biz_id']);
		$db->autoExecute($as->table('biz_zone'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($as->table('biz_zone'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_biz_zone($inf=array(),$inf_arr=array()){//编辑商业区列表
	global $db,$as;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['biz_id']);
		$db->autoExecute($as->table('biz_zone'), $inf_ok, 'UPDATE', 'biz_id = ' . $inf['biz_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($as->table('biz_zone'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_biz_zone($biz_id){//删除商业区列表
	global $db,$as;
	if(empty($biz_id)){return false;}

	$db->query("delete from ".$as->table('biz_zone')." where biz_id='$biz_id'");
    return true;	
}

function get_biz_zone($biz_id){//读取商业区列表
	global $db,$as;
	$res=array();
	if(empty($biz_id)){return $res;}
	
	$res=$db->getRow("select * from ".$as->table('biz_zone')."  where biz_id='$biz_id'");
	return $res;	
}

//------------------------------------------------------ -----------------


/**
 * 酒店列表
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */
function get_hotel_list($srch_param, $size=10, $page=1, $sort='booking_times', $order='desc',$is_all=0)
{
	global $db,$ecs,$as;
    if(empty($srch_param)){return array();}
    extract($srch_param);
    
    $where = " where 1 and cat_id='".HOTEL_CAI_ID."' ";

    
    if (!empty($city_name)){$where.=" and city_name like '%".$city_name."%'";}
    if (!empty($city_name_cn)){$where.=" and city_name_cn='".$city_name_cn."'";}
    if (!empty($city_name_cn_like)){$where.=" and city_name_cn like '%".$city_name_cn_like."%'";}
    if (!empty($goods_name)){$where.=" and goods_name like '%".$goods_name."%'";}
    if (!empty($hotel_name)){$where.=" and goods_name like '%".$hotel_name."%'";}
    if (!empty($serve_item)){$where.=" and serve_item like '%".$serve_item."%'";}
    if (!empty($food_establishment)){$where.=" and food_establishment like '%".$food_establishment."%'";}
    if (!empty($establishment)){$where.=" and establishment like '%".$establishment."%'";}
    if (!empty($credit_card)){$where.=" and credit_card like '%".$credit_card."%'";}
    if (!empty($position_txt)){$where.=" and (near_txt like '%".$position_txt."%' or position_txt like '%".$position_txt."%')";}
    if (!empty($near_txt)){$where.=" and (near_txt like '%".$near_txt."%' or position_txt like '%".$near_txt."%')";}
    if (!empty($is_on_sale_txt)){
    	if($is_on_sale_txt=='all'){
    		$where.=" and is_on_sale_txt <>'关闭'";
    	}else{
    		$where.=" and is_on_sale_txt ='".$is_on_sale_txt."'";
    	}
    }else{$where.=" and (is_on_sale_txt <>'关闭' or is_on_sale_txt is NULL)";}
    if (!empty($english_name)){$where.=" and (spell_cn like '%".$english_name."%' or english_name like '%".$english_name."%')";}
    if (!empty($spell_cn)){$where.=" and (spell_cn like '%".$spell_cn."%' or english_name like '%".$spell_cn."%')";}
    if (!empty($bank_suport)){$where.=" and bank_suport like '%".$bank_suport."%'";}
    if (!empty($is_hot)){$where.=" and is_hot='".$is_hot."'";}
    if (!empty($nation_id)){$where.=" and nation_id='".$nation_id."'";}
    if (!empty($province_id)){$where.=" and province_id='".$province_id."'";}
    if (!empty($biz_area_id)){$where.=" and biz_area_id='".$biz_area_id."'";}
    if (!empty($area_id)){$where.=" and area_id='".$area_id."'";}
    if (!empty($city_id)){$where.=" and city_id='".$city_id."'";}
    if (!empty($hc_id)){$where.=" and hc_id='".$hc_id."'";}
    if (!empty($hotel_star)){$where.=" and hotel_star='".$hotel_star."'";}
    if (!empty($hotel_star_1)){$where.=" and hotel_star>='".$hotel_star_1."'";}
    if (!empty($hotel_star_2)){$where.=" and hotel_star<='".$hotel_star_2."'";}
    if (!empty($multiple_id)){$where.=" and multiple_id='".$multiple_id."'";}
    if (!empty($room_price_min)){$where.=" and room_price_min>='".$room_price_min."'";}
    if (!empty($room_price_max)){$where.=" and room_price_max<='".$room_price_max."'";}

    $sql='';
    $sql = 'select count(*) as num FROM ' . $ecs->table('goods') . ' AS g ' .
            'LEFT JOIN (select hc_id as hc_id_hc,city_name,city_name_cn,hc_id_from,father_id from ' . $as->table('hotel_city') . ") AS hc ON hc.hc_id_hc = g.hc_id " .
            'LEFT JOIN (select areaID,area from ' . $as->table('area') . ") AS ar ON ar.areaID = g.area_id " .
            'LEFT JOIN (select biz_id,biz_name from ' . $as->table('biz_zone') . ") AS bz ON bz.biz_id = g.biz_area_id " .
            " $where";
    $count=$db->getOne($sql);//总记录数
    /* 获得商品列表 */
    $sql = 'SELECT * FROM ' . $ecs->table('goods') . ' AS g ' .
            'LEFT JOIN (select hc_id as hc_id_hc,city_name,city_name_cn,hc_id_from,father_id from ' . $as->table('hotel_city') . ") AS hc ON hc.hc_id_hc = g.hc_id " .
            'LEFT JOIN (select areaID,area from ' . $as->table('area') . ") AS ar ON ar.areaID = g.area_id " .
            'LEFT JOIN (select biz_id,biz_name from ' . $as->table('biz_zone') . ") AS bz ON bz.biz_id = g.biz_area_id " .
            " $where  ORDER BY $sort $order ";
    if($is_all){
    	$res = $db->query($sql);
    	
    }else{
    	$res = $db->selectLimit($sql, $size, ($page - 1) * $size);
    }
    
    
    $arr = array();
    $i=0;
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
    	switch ($row['hotel_star']){
    		case '1':
    			$row['hotel_star_txt']='一星级';
    			break;
    		case '2':
    			$row['hotel_star_txt']='二星级';
    			break;
    		case '3':
    			$row['hotel_star_txt']='三星级';
    			break;
    		case '4':
    			$row['hotel_star_txt']='四星级';
    			break;
    		case '5':
    			$row['hotel_star_txt']='五星级';
    			break;
    			
    	}
    	$row['goods_desc_short']=sub_str($row['goods_desc'],70);
    	$row['key']=++$i;
        $arr['list'][]=$row;
        
    }
    $arr['count']=$count;
    return $arr;
}

//------------------------------------------------------ -----------------



function get_goods($goods_id){//读取商品信息
	global $db,$ecs,$as;
	$res=array();
	if(empty($goods_id)){return $res;}
	
	$res=$db->getRow('SELECT * FROM ' . $ecs->table('goods') . ' AS g ' .
            'LEFT JOIN (select hc_id as hc_id_hc,city_name,city_name_cn,hc_id_from,father_id from ' . $as->table('hotel_city') . ") AS hc ON hc.hc_id_hc = g.hc_id " .
            'LEFT JOIN (select areaID,area from ' . $as->table('area') . ") AS ar ON ar.areaID = g.area_id " .
            'LEFT JOIN (select biz_id,biz_name from ' . $as->table('biz_zone') . ") AS bz ON bz.biz_id = g.biz_area_id where goods_id='$goods_id'");
	
	$credit_card_arr=array();
	$credit_card_arr=explode(',',$res['credit_card']);
	$res['credit_card']=array();
	//信用卡（１境外发行信用卡=万事达(Master)，２境外发行信用卡 =威士(VISA)，３境外发行信用卡= 运通(AMEX)，
	//４境外发行信用卡 =大来(Diners Club)，５境外发行信用卡=JCB，６国内发行银联卡）
	if(!empty($credit_card_arr)){
		foreach ($credit_card_arr as $key2=>$val2){
			$val2=trim($val2);
			switch ($val2){//
				case '1':
					$res['credit_card'][]=array('name'=>'万事达(Master)(境外发行信用卡)','val'=>'Master');
					break;
				case '2':
					$res['credit_card'][]=array('name'=>'威士(VISA)(境外发行信用卡)','val'=>'VISA');
					break;
				case '3':
					$res['credit_card'][]=array('name'=>'运通(AMEX)(境外发行信用卡)','val'=>'AMEX');
					break;
				case '4':
					$res['credit_card'][]=array('name'=>'大来(Diners Club)(境外发行信用卡)','val'=>'DinersClub');
					break;
				case '5':
					$res['credit_card'][]=array('name'=>'JCB(境外发行信用卡)','val'=>'JCB');
					break;
				case '6':
					$res['credit_card'][]=array('name'=>'中国银联卡(国内发行信用卡)','val'=>'unionPay');
					break;
			}
		}
	}
	return $res;
}

//------------------------------------------------------ -----------------
function get_goods_img_list($goods_id,$page=1,$page_num=10,$all=0){//读取商品相册列表，
	global $db,$ecs,$as;

	$res=array();
	if(empty($goods_id)){return $res;}
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	
	$sql = "select count(*) as num from".$ecs->table('goods_gallery')." where goods_id='".$goods_id."' ";       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	 $sql ="select * from  ".$ecs->table('goods_gallery')." where goods_id='".$goods_id."' ".$limit;
	
    $res=$db->getAll($sql);
/*
    foreach ($res as $key=>$val){

    	$res[$key]=$val;
    }*/
	return $res;
}
//------------------------------------------

/**
 * 评论列表
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */
function get_comment_list_as($srch_param, $size=20, $page=1, $sort='comment_id', $order='desc')
{
	global $db,$ecs,$as;
    if(empty($srch_param)){return array();}
    extract($srch_param);
    
    $where = " where 1 ";

    
    if ($comment_type!=''){$where.=" and comment_type='".$comment_type."'";}
    if (!empty($id_value)){$where.=" and id_value='".$id_value."'";}
    if (!empty($status)){$where.=" and status='".$status."'";}

    $sql='';
    $sql = 'select count(*) as num,sum(server_rank) as server_rank_total,sum(clean_rank) as clean_rank_total
  ,sum(establishment_rank) as establishment_rank_total,sum(price_rank) as price_rank_total FROM ' . $ecs->table('comment') .$where;
    $count_arr=$db->getRow($sql);//总记录数
    $count=$count_arr['num'];
    
    /* 获得商品列表 */
    $sql = 'SELECT * FROM ' . $ecs->table('comment') . " $where  ORDER BY $sort $order ";
    $res = $db->selectLimit($sql, $size, ($page - 1) * $size);
    
    $arr = array();
    $i=0;
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
    	if($row['add_time']>0){$row['add_time_txt']=date('Y-m_d',$row['add_time']);}
    	
    	$row['server_rank']=$row['server_rank']*2;
    	$row['clean_rank']=$row['clean_rank']*2;
    	$row['establishment_rank']=$row['establishment_rank']*2;
    	$row['price_rank']=$row['price_rank']*2;
    	$row['total_rank']=sprintf('%.1f',($row['server_rank']+$row['clean_rank']+$row['establishment_rank']+$row['price_rank'])/4);
    	
    	//刻度值
    	$row['server_rank_val']=$row['server_rank']*5;
    	$row['clean_rank_val']=$row['clean_rank']*5;
    	$row['establishment_rank_val']=$row['establishment_rank']*5;
    	$row['price_rank_val']=$row['price_rank']*5;
    	$row['total_rank_val']=$row['total_rank']*5;
    	
    	$row['key']=++$i;
        $arr['list'][]=$row;   
    }
    $arr['count']=$count;
    if($count>0){
    	$arr['server_rank_averag']=sprintf('%.2f',$count_arr['server_rank_total']/$count)*2;
    	$arr['clean_rank_averag']=sprintf('%.2f',$count_arr['clean_rank_total']/$count)*2;
    	$arr['establishment_rank_averag']=sprintf('%.2f',$count_arr['establishment_rank_total']/$count)*2;
    	$arr['price_rank_averag']=sprintf('%.2f',$count_arr['price_rank_total']/$count)*2;
    	$arr['hotel_comment_averag']=sprintf('%.2f',($count_arr['server_rank_total']+$count_arr['clean_rank_total']+$count_arr['establishment_rank_total']+$count_arr['price_rank_total'])/($count*4))*2;
    	//刻度值
    	$arr['server_averag_val']=$arr['server_rank_averag']*10;
    	$arr['clean_averag_val']=$arr['clean_rank_averag']*10;
    	$arr['establishment_averag_val']=$arr['establishment_rank_averag']*10;
    	$arr['price_averag_val']=$arr['price_rank_averag']*10;
    	$arr['hotel_averag_val']=$arr['hotel_comment_averag']*10;
    }else{
    	$arr['server_rank_averag']='暂无点评';
    	$arr['clean_rank_averag']='暂无点评';
    	$arr['establishment_rank_averag']='暂无点评';
    	$arr['price_rank_averag']='暂无点评';
    	$arr['hotel_comment_averag']='暂无点评';
    	
    	$arr['server_averag_val']=0;
    	$arr['clean_averag_val']=0;
    	$arr['establishment_averag_val']=0;
    	$arr['price_averag_val']=0;
    	$arr['hotel_averag_val']=0;
    }
    
    
    return $arr;
}

function add_comment($inf=array(),$inf_arr=array()){//添加评论
	global $db,$as,$ecs;
	if(empty($inf['content'])&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['comment_id']);
		$db->autoExecute($ecs->table('comment'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($ecs->table('comment'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
//------------------------------------------

function get_multiple_list($search_inf=array(),$page=1,$page_num=10,$all=1){//读取连锁品牌列表列表，
	global $db,$ecs,$as;

	$res=array();
	if((!is_numeric($page))||$page<1) {
		$page=1;
	}
	if((!is_numeric($page_num))||$page_num<1) {
		$page_num=10;
	}
	$sql ="";
	$wh=" where 1 ";
	if(!empty($search_inf['start_grade'])){$wh.=" and start_grade='".$search_inf['start_grade']."'";}
	if(!empty($search_inf['mt_name'])){$wh.=" and mt_name like '%".$search_inf['mt_name']."%'";}
	
	$sql = "select count(mt_id) as num from " .$as->table('multiple').$wh;       
	
	$num_db=$db->getOne($sql);//总记录数
	$page_db=intval($num_db/$page_num)+(fmod($num_db,$page_num)==0?0:1);//总页数
	if($page>$page_db){$page=$page_db;}//如果要显示的页数超过总页数，

	$limit_f=(($page-1)*$page_num)<0?0:($page-1)*$page_num;
	$limit=" limit ".$limit_f.",".$page_num;
	if($all==1){$limit="";}
	$sql ="select * from  ".$as->table('multiple').$wh." order by start_grade desc ".$limit;
	
    $res=$db->getAll($sql);
/*
    foreach ($res as $key=>$val){

    	$res[$key]=$val;
    }*/
	return $res;
}

function add_multiple($inf=array(),$inf_arr=array()){//添加连锁品牌列表
	global $db,$as;
	if(empty($inf)&&empty($inf_arr)){return false;}

	if(!empty($inf)){
		unset($inf['mt_id']);
		$db->autoExecute($as->table('multiple'), $inf, 'INSERT');
		$id=mysql_insert_id();
		return $id;
	}else{
		if(!empty($inf_arr)){
			$db->autoExecute($as->table('multiple'), $inf_arr, 'INSERT','','',true);
			return true;
		}
	}
   
}
function edt_multiple($inf=array(),$inf_arr=array()){//编辑连锁品牌列表
	global $db,$as;

	if(!empty($inf)){
		$inf_ok=$inf;
		unset($inf_ok['mt_id']);
		$db->autoExecute($as->table('multiple'), $inf_ok, 'UPDATE', 'mt_id = ' . $inf['mt_id']);
		return true;
	}else{
		if(!empty($inf_arr)){//更新记录的条件是$inf_arr[i]['where']
			//print_r($inf_arr);
			$db->autoExecute($as->table('multiple'), $inf_arr, 'UPDATE','','',true);
			return true;
		}
	}
	
}

function del_multiple($mt_id){//删除连锁品牌列表
	global $db,$as;
	if(empty($mt_id)){return false;}

	$db->query("delete from ".$as->table('multiple')." where mt_id='$mt_id'");
    return true;	
}

function get_multiple($mt_id){//读取连锁品牌列表
	global $db,$as;
	$res=array();
	if(empty($mt_id)){return $res;}
	
	$res=$db->getRow("select * from ".$as->table('multiple')."  where mt_id='$mt_id'");
	return $res;	
}

//------------------------------------------
//------------------------------------------
?>